home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / MATV.ZIP / REDIR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-10  |  991 b   |  56 lines

  1.  
  2. #include "redir.h"
  3. #include "stdio.h"
  4.  
  5. void Redirector::rdopen(char *fid)
  6. {
  7.    if (onoff == 1) exit(1);
  8.    onoff = 1;
  9.    // note 1 is file handle for stdout
  10.    // redirect stdout to output file
  11.    
  12.    if (- 1 == (fout = open(fid,
  13.             O_CREAT | O_TEXT | O_WRONLY, S_IWRITE)))
  14.       exit(1);
  15.    oldstdout = dup(1);
  16.    dup2(fout, 1);
  17.    close(fout);
  18. }
  19. void Redirector::rdclose(void)
  20. {
  21.    if (onoff == 0) exit(1);
  22.    onoff = 0;
  23.    // recapture stdout
  24.    dup2(oldstdout, 1);
  25.    close(oldstdout);
  26. }
  27. /*
  28. main()
  29. {
  30. Redirector junk("c:\\math\\bump\\stdout.dat");
  31. cout << "silly silly silly silly" << endl;
  32. for( int i=1; i<20; i++ ) cout << i << endl;
  33. junk.rdclose();
  34. for( int j=1; j<20; j++ ) cout << j << endl;
  35.  
  36. return 0;
  37. }
  38.  
  39. main()
  40. {
  41. filebuf test;
  42. test.open("ss.out",ios::out);
  43. ostream_withassign x;
  44. x = cout;
  45. x << "hi guy";
  46. cout = &test;
  47. cout << "buy buy guy";
  48. x << "hi guy";
  49. cout = x;
  50. cout << "but guy?";
  51.  
  52. test.close();
  53. return 0;
  54. }
  55. */
  56.